<?php
$path02 = "FileUpload/Slider";

$NoAnh02 = 0;
$filesAnh02 = array();
if ($handleFile02 = opendir($path02)) {
    while (false !== ($fileAnh = readdir($handleFile02))) {
        if ($fileAnh != "." && $fileAnh != ".." && (preg_match("/\.jpg|\.gif|\.png/i", $fileAnh))) {
            $NoAnh02++;
            array_push($filesAnh02, $fileAnh);
        }
    }
    closedir($handleFile02);
}
?>
<div class="before-content-home">
    <div class="container_12 clearfix">
        <div class="grid_8">
            <section id="slider-wrapper">
                <div class="flexslider-holder">
                    <div class="flexslider-container">
                        <div class="slider-wrapper theme-default">
                            <div id="slider" class="nivoSlider">
                                <?php for ($i = 0; $i < $NoAnh02; $i++) { ?>
                                    <img src="<?php echo $path02 . "/" . $filesAnh02[$i]; ?>"/>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<div class="container_12 primary_content_wrap clearfix">
    <div class="clearfix">
        <div class="top-content">
            <div class="grid_12">
                <div class="widget-main" id="my_poststypewidget-3">
                    <ul class="post_list home-latest">
                        <li class="cat_post_item-1 clearfix">
                            <figure class="featured-thumbnail">
                                <a href="product.php">
                                    <img alt="" src="images/product.jpg">
                                </a>
                            </figure>
                            <div class="extra-wrap">
                                <div class="post-meta-wrapper">
                                </div>
                                <h5><a title="" rel="bookmark"
                                       href="product.php"
                                       class="post-title">Sản phẩm</a></h5>

                                <div class="post_content">
                                    Các sản phẩm điện thoại mới nhất
                                    <a class="link-1"
                                        href="product.php">xem thêm</a>
                                </div>
                                <div class="shop-options">
                                </div>
                            </div>
                        </li>
                        <li class="cat_post_item-2 clearfix">
                            <figure class="featured-thumbnail">
                                <a href="news.php">
                                    <img alt=""
                                         src="images/tintuc.jpg">
                                </a>
                            </figure>
                            <div class="extra-wrap">
                                <div class="post-meta-wrapper">
                                </div>
                                <h5><a title="" rel="bookmark"
                                       href="news.php"
                                       class="post-title">Tư vấn - Tin tức</a></h5>

                                <div class="post_content">
                                    Hãy để chúng tôi tư vấn cho bạn.
                                    <a class="link-1"
                                        href="news.php">xem thêm</a>
                                </div>
                                <div class="shop-options">
                                </div>
                            </div>
                        </li>
                        <li class="cat_post_item-3 clearfix nomargin">
                            <figure class="featured-thumbnail">
                                <a href="policy.php">
                                    <img alt=""
                                         src="images/shipping.jpg">
                                </a>
                            </figure>
                            <div class="extra-wrap">
                                <div class="post-meta-wrapper">
                                </div>
                                <h5><a title="Sunt in culpa" rel="bookmark"
                                       href="policy.php"
                                       class="post-title">Chính sách - Vận chuyển</a></h5>

                                <div class="post_content">
                                    Chính sách giao hàng.
                                    <a
                                        class="link-1"
                                        href="policy.php">xem thêm</a>
                                </div>
                                <div class="shop-options">
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="clear"></div>
        </div>
        <div class="home-page-content">
            <div class="grid_12">
                <div class="widget-main" id="my_poststypewidget-4"><h3>Sản phẩm mới</h3>
                    <ul class="post_list recent_products">
                        <?php
                        include 'mySQLConnect.php';
                        $sql3 = "SELECT * FROM  product ORDER BY date DESC LIMIT 0,4";

                        $result3 = mysql_query($sql3);
                        $count = 0;
                        while ($row3 = mysql_fetch_array($result3)) {
                            $count++;
                            $image_url = $row3['image_url'];

                            if (strpos($image_url, '../') !== false) {
                                $image_url = substr($image_url, 3);
                            }

							$price = ($row3['price']);
						$temp = "";
                            $price = strrev($price);
                        while (strlen($price) >= 4) {							
                            $temp = $temp . substr ($price,0,3) . '.';
							$price = substr ($price,3);
                        }
						
						if (strlen($price) == 0){
							$price = strrev($temp);
						} else {
							$price = strrev($price) . strrev($temp);
						}
                            ?>
                            <li class="cat_post_item-1 clearfix">
                                <figure class="featured-thumbnail">
                                    <a href="detailProduct.php?id=<?php echo $row3['id'] ?>">
                                        <img alt="Flower Shop"
                                             src="<?php echo $image_url; ?>">
                                    </a>
                                </figure>
                                <div class="extra-wrap">
                                    <div class="post-meta-wrapper">
                                    </div>
                                    <h5><a title="Flower Shop" rel="bookmark"
                                           href="detailProduct.php?id=<?php echo $row3['id'] ?>"
                                           class="post-title"><?php echo urldecode($row3['name']) ?></a></h5>

                                    <div class="post_content">
                                    </div>
                                    <div class="shop-options">
                                        <div class="prod_price">
                                            <span class="price"><?php echo $price ?> VND</span></div>
                                    </div>
                                </div>
                            </li>
                        <?php
                        }

                        if ($count == 0) {
                            echo 'sản phẩm đang được cập nhật';
                        }

                        include 'mySQLClose.php';
                        ?>
                    </ul>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>
